package com.atguigu.future;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

@Slf4j
public class ICompleableFuture {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            log.info("异步线程有返回值");
            return "A";
        });

        CompletableFuture<String> completableFuture1 = completableFuture.thenApplyAsync(a -> {
            log.info("串行有返回值");
            return a + ":-------------B";
        });
        CompletableFuture<Void> co = completableFuture.thenAccept(a -> {
            log.info("串行无返回值");
        });
        CompletableFuture<Void> thenRun = completableFuture.thenRun(() -> {
            log.info("ThenRun-----------------");
        });

        CompletableFuture<Void> runAsync = CompletableFuture.runAsync(() -> {
            log.info("异步线程无返回值");
        });

        CompletableFuture.allOf(completableFuture,completableFuture1,co,thenRun,runAsync).join();
//  CompletableFuture.anyOf(completableFuture,completableFuture1,co,thenRun,runAsync).join();
    log.info("主线程继续");
//        String s = completableFuture.get();
//        runAsync.get();
//        co.get();
//        log.info("我是异步线程:{}",s);
//        String s1 = completableFuture1.get();
//        log.info("我是有返回值的:{}",s1);
    }
}
